package com.crane.oss.sports;

import com.crane.common.framework.http.apache.HttpClientUtils;
import com.crane.common.framework.http.apache.HttpResult;
import com.crane.oss.xunfei.req.QueryStudentAttendanceDetailReq;
import com.crane.oss.xunfei.req.QueryStudentAttendanceHistoryReq;
import com.crane.oss.xunfei.req.QueryStudentAttendanceReq;
import com.crane.oss.xunfei.req.UpdateStudentAttendanceDetailReq;
import com.crane.oss.xunfei.resp.*;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zx
 */
@Component
public class XunFeiAttendanceApiService extends XunFeiApiService {
    /**
     * 查询班级学生考勤情况
     *
     * @param request
     * @param uid
     * @return
     */
    public ApiListResponse<StudentClassAttendanceResp> getStudentAttendance(QueryStudentAttendanceReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/student/attendance/info", params);
        if (httpResult.isSuccess()) {
            ApiListResponse<StudentClassAttendanceResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<StudentClassAttendanceResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 查询课堂学生考勤情况
     */
    public ApiListResponse<StudentAttendanceDetailResp> getStudentAttendanceDetail(QueryStudentAttendanceDetailReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/student/attendance/detail/" + request.getCourseId(), params);
        if (httpResult.isSuccess()) {
            ApiListResponse<StudentAttendanceDetailResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<StudentAttendanceDetailResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }


    /**
     * 修改课堂学生考勤情况
     */
    public ApiSingleResponse<String> updateStudentAttendance(UpdateStudentAttendanceDetailReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.post(xunFeiAppConfig.getUrl() + "/student/attendance/update", params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<String> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<String>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }


    /**
     * 获取学生考勤列表
     */
    public ApiListResponse<StudentAttendanceHistoryResp> getStudentAttendanceHistory(QueryStudentAttendanceHistoryReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/student/attendance/history", params);
        if (httpResult.isSuccess()) {
            ApiListResponse<StudentAttendanceHistoryResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<StudentAttendanceHistoryResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 获取学生考勤统计
     */
    public ApiSingleResponse<StudentAttendanceStatisticResp> getStudentAttendanceStatistic(QueryStudentAttendanceHistoryReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/student/attendance/statistic", params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<StudentAttendanceStatisticResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<StudentAttendanceStatisticResp>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }



    public static void main(String[] args) {
        XunFeiAttendanceApiService xunFeiApiService=new XunFeiAttendanceApiService();
        QueryStudentAttendanceHistoryReq queryStudentAttendanceHistoryReq=new QueryStudentAttendanceHistoryReq();
        queryStudentAttendanceHistoryReq.setStudentId("1");
        queryStudentAttendanceHistoryReq.setTeachCycleId("1");
//        queryStudentAttendanceHistoryReq.setBeginTime(1649232409000L);
//        queryStudentAttendanceHistoryReq.setEndTime(1654502809000L);
        //System.out.println(xunFeiApiService.getStudentAttendanceHistory(queryStudentAttendanceHistoryReq,"87", null,"3"));

        System.out.println(xunFeiApiService.getStudentAttendanceStatistic(queryStudentAttendanceHistoryReq,"87", null,"3"));

    }

}

